/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package app;

import fuzzyLogic.*;

/**
 *
 * @author CygiDawid
 */
public class MyFuzzyLogic extends FuzzyLogic {
    //<editor-fold defaultstate="collapsed" desc="FinalStaticFields">
    private final static String STEER = "steer";
    private final static String STEER1 = "maxLeft";
    private final static String STEER2 = "softLeft";
    private final static String STEER3 = "straight";
    private final static String STEER4 = "softRight";
    private final static String STEER5 = "maxRight";
    
    private final static String ACCELERATION = "acceleration";
    private final static String ACCELERATION1 = "maxBreak";
    private final static String ACCELERATION2 = "break";
    private final static String ACCELERATION3 = "clutch";
    private final static String ACCELERATION4 = "slow";
    private final static String ACCELERATION5 = "max";
    
    private final static String ANGLE = "angle";
    private final static String ANGLE1 = "front";
    private final static String ANGLE2 = "sideFront";
    private final static String ANGLE3 = "side";
    private final static String ANGLE4 = "sideBack";
    private final static String ANGLE5 = "back";
    
    private final static String SPEED = "speed";
    private final static String SPEED1 = "fastBack";
    private final static String SPEED2 = "slowBack";
    private final static String SPEED3 = "stop";
    private final static String SPEED4 = "slowFront";
    private final static String SPEED5 = "fastFront";
    //**************** Group 1
    //private LinguisticVariable _acc;
    //private LinguisticVariable _angle;
    //private LinguisticVariable _speed;
    //****************
    //**************** Group 2
    //private LinguisticVariable _steer;
    // //private LinguisticVariable _angle;
    // //private LinguisticVariable _speed;
    //****************
    //</editor-fold>
    
    
    public MyFuzzyLogic() {
        createSets();
        createRules();
    }
    
    private void createSets() {/*
        LinguisticVariable steer = new LinguisticVariable(STEER, -100d, 100d);
        steer.addSet(STEER1, -100d, -100d, -67d);
        steer.addSet(STEER2, -100d, -67d, -33d, 0d);
        steer.addSet(STEER3, -33d, 0d, 33d);
        steer.addSet(STEER4, 0d, 33d, 67d, 100d);
        steer.addSet(STEER5, 67d, 100d, 100d);
        addVariable(steer);*/
        
        LinguisticVariable angle = new LinguisticVariable(ANGLE, 0d, 180d);
        angle.addSet(ANGLE1, 0d, 0d, 30d);
        angle.addSet(ANGLE2, 0d, 30d, 60d, 90d);
        angle.addSet(ANGLE3, 60d, 90d, 120d);
        angle.addSet(ANGLE4, 90d, 120d, 150d, 180d);
        angle.addSet(ANGLE5, 150d, 180d, 180d);
        addVariable(angle);
        
        LinguisticVariable speed = new LinguisticVariable(SPEED, -100d, 100d);
        speed.addSet(SPEED1, -100d, -100d, -67d);
        speed.addSet(SPEED2, -100d, -67d, -33d, 0);
        speed.addSet(SPEED3, -33d, 0d, 33d);
        speed.addSet(SPEED4, 0d, 33d, 67d, 100d);
        speed.addSet(SPEED5, 67d, 100d, 100d);
        addVariable(speed);
        
        LinguisticVariable acceleration = new LinguisticVariable(ACCELERATION, -100d, 100d);
        acceleration.addSet(ACCELERATION1, -100d, -100d, -67d);
        acceleration.addSet(ACCELERATION2, -100d, -67d, -33d, 0d);
        acceleration.addSet(ACCELERATION3, -33d, 0d, 33d);
        acceleration.addSet(ACCELERATION4, 0d, 33d, 67d, 100d);
        acceleration.addSet(ACCELERATION5, 67d, 100d, 100d);
        addVariable(acceleration);
    }
    
    private void createRules() {
        addRule(new FuzzyRule(ANGLE1, FuzzyOperator.And, SPEED1, ACCELERATION5)); // angle == front
        addRule(new FuzzyRule(ANGLE1, FuzzyOperator.And, SPEED2, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE1, FuzzyOperator.And, SPEED3, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE1, FuzzyOperator.And, SPEED4, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE1, FuzzyOperator.And, SPEED5, ACCELERATION5));
        
        addRule(new FuzzyRule(ANGLE2, FuzzyOperator.And, SPEED1, ACCELERATION5)); // angle == sideFront
        addRule(new FuzzyRule(ANGLE2, FuzzyOperator.And, SPEED2, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE2, FuzzyOperator.And, SPEED3, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE2, FuzzyOperator.And, SPEED4, ACCELERATION4));
        addRule(new FuzzyRule(ANGLE2, FuzzyOperator.And, SPEED5, ACCELERATION3));
        
        addRule(new FuzzyRule(ANGLE3, FuzzyOperator.And, SPEED1, ACCELERATION5)); // angle == side
        addRule(new FuzzyRule(ANGLE3, FuzzyOperator.And, SPEED2, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE3, FuzzyOperator.And, SPEED3, ACCELERATION4));
        addRule(new FuzzyRule(ANGLE3, FuzzyOperator.And, SPEED4, ACCELERATION3));
        addRule(new FuzzyRule(ANGLE3, FuzzyOperator.And, SPEED5, ACCELERATION2));
        
        addRule(new FuzzyRule(ANGLE4, FuzzyOperator.And, SPEED1, ACCELERATION5)); // angle == sideBack
        addRule(new FuzzyRule(ANGLE4, FuzzyOperator.And, SPEED2, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE4, FuzzyOperator.And, SPEED3, ACCELERATION4));
        addRule(new FuzzyRule(ANGLE4, FuzzyOperator.And, SPEED4, ACCELERATION2));
        addRule(new FuzzyRule(ANGLE4, FuzzyOperator.And, SPEED5, ACCELERATION1));
        
        addRule(new FuzzyRule(ANGLE5, FuzzyOperator.And, SPEED1, ACCELERATION5)); // angle == back
        addRule(new FuzzyRule(ANGLE5, FuzzyOperator.And, SPEED2, ACCELERATION5));
        addRule(new FuzzyRule(ANGLE5, FuzzyOperator.And, SPEED3, ACCELERATION4));
        addRule(new FuzzyRule(ANGLE5, FuzzyOperator.And, SPEED4, ACCELERATION1));
        addRule(new FuzzyRule(ANGLE5, FuzzyOperator.And, SPEED5, ACCELERATION1));
        
        // IF 'angle' IS 'behind' AND 'speed' IS 'slowForeward' THEN 'acceleration' IS 'clutch'
        // itp. (...)
    }
}
